<?php

declare(strict_types=1);

namespace App\Orchid\Screens;

use Orchid\Screen\Screen;
use Orchid\Support\Facades\Layout;
use Orchid\Screen\Actions\Button;
use App\Models\Post;
use App\Models\Page;
use App\Models\User;

class PlatformScreen extends Screen
{
    /**
     * Fetch data to be displayed on the screen.
     *
     * @return array
     */
    public function query(): iterable
    {
        return [
            'posts_count' => Post::count(),
            'pages_count' => Page::count(),
            'users_count' => User::count(),
        ];
    }

    /**
     * The name of the screen displayed in the header.
     */
    public function name(): ?string
    {
        return '仪表盘';
    }

    /**
     * Display header description.
     */
    public function description(): ?string
    {
        return '欢迎来到CMS管理系统';
    }

    /**
     * The screen's action buttons.
     *
     * @return \Orchid\Screen\Action[]
     */
    public function commandBar(): iterable
    {
        return [
            Button::make('创建文章')
                ->icon('pencil')
                ->route('platform.posts.create'),
        ];
    }

    /**
     * The screen's layout elements.
     *
     * @return \Orchid\Screen\Layout[]
     */
    public function layout(): iterable
    {
        return [
            Layout::metrics([
                '文章总数' => 'posts_count',
                '页面总数' => 'pages_count',
                '用户数' => 'users_count',
            ]),
        ];
    }

}
